package com.fh.shop.api.mq.producer;

import com.fh.shop.config.MQConstant;
import org.springframework.amqp.AmqpException;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessagePostProcessor;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class OrderProducer {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    public void sendOrderMessage(String orderId,String expire){
        rabbitTemplate.convertAndSend(MQConstant.orderDirect.EX, MQConstant.orderDirect.ROUTE_KEY, orderId, new MessagePostProcessor() {
            @Override
            public Message postProcessMessage(Message message) throws AmqpException {
                //默认时间 毫秒
                message.getMessageProperties().setExpiration(expire);
                return message;
            }
        });
    }
}
